package com.app.micaihu.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.app.micaihu.R;
import com.app.micaihu.ad.AdConfig;
import com.app.micaihu.ad.toutiao.ToutiaoAdManager;
import com.app.micaihu.ad.toutiao.ToutiaoCloseDialog;
import com.app.micaihu.ad.toutiao.ToutiaoNativeAd;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.ad.NativeAd;
import com.app.micaihu.bean.news.NewsEntity;
import com.app.micaihu.bean.news.ViewGameVideoSmallImg;
import com.app.micaihu.bean.news.ViewGameVideoThree;
import com.app.micaihu.bean.news.ViewNewsBigImg;
import com.app.micaihu.bean.news.ViewNewsNoImg;
import com.app.micaihu.bean.news.ViewNewsSmallImg;
import com.app.micaihu.bean.news.ViewNewsThreeImg;
import com.app.micaihu.bean.news.ViewNewsTopicBig;
import com.app.micaihu.bean.news.ViewNewsTopicSmall;
import com.app.micaihu.bean.news.ViewVideoSmallImg;
import com.app.micaihu.configure.Config;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.configure.UmEventId;
import com.app.micaihu.utils.MobclickAgentUtils;
import com.blankj.utilcode.util.LogUtils;
import com.bytedance.sdk.openadsdk.FilterWord;
import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
import com.jeremyliao.liveeventbus.LiveEventBus;

import java.util.HashMap;
import java.util.List;

//import com.baidu.mobad.feeds.NativeResponse;

/**
 * 相关新闻的适配器
 * 相关新闻的样式和新闻列表的样式是有区别的
 *
 * @author linkai
 */
public class NewsAboutAdapter extends AppBaseAdapter<NewsEntity> {

    private static final int NEWS_NO_IMAGE = 0;// 文章没有图片
    private static final int NEWS_ONE_IMAGE = 1;// 文章一个图片
    private static final int NEWS_THREE_IMAGE = 2;// 文章三个图片
    private static final int NEWS_BIG_IMAGE = 3;// 文章大图(文章  图集 视频)
    private static final int VIDEO_ONE_IMAGE = 4;// 视频一张图
    private static final int AD_SMALL_BAIDU = 5;//百度小广告类型
    private static final int AD_BIG_BAIDU = 6;//百度大广告类型
    private static final int AD_BIG_GDT = 7;//广电通大广告类型
    private static final int AD_SMALL_GDT = 8;//广点通小广告类型
    private static final int GAMEN_PIC_NEWS = 10;//游戏图片直接下载,适配文章列表
    private static final int GAMEN_VIDEO_SMALL = 11;//游戏小图视频类型
    private static final int GAMEN_VIDEO_CUSTOM = 12;//游戏大图视频类型
    private static final int NEWS_THREE_IMAGE_WITH_NUM = 13;//三图待图片数量角标
    private static final int DEFAULT = 9;//没有匹配到类型
    private static final int AD_TT_SMALL = 14;  //头条小图
    private static final int AD_TT_BIG = 15; //头条大图
    private static final int TOPIC_BIG = 21;//话题大图
    private static final int TOPIC_SMALL = 22;//话题小图

    public NewsAboutAdapter(List<NewsEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        // 获取position对应的数据
        NewsEntity news = list.get(position);
        if (news == null) {
            news = new NewsEntity();
        }
//        LogUtils.e("gzq","creatView = "+ news.getNativeAd() +"      posi = "+ position);
        //首先判断该数据是否为 广告
        if (news.getNativeAd() != null && !TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_H5)
                && !TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_TOUTIAO)) {
            View view = AdConfig.getAboutNativeAdView(context, news.getNativeAd(), position, convertView, UmEventId.INSTANCE.getArticleabout());
            if (view != null && view.getTag() != null) {
                return view;
            } else {
                return inflater.inflate(R.layout.item_layout_gone, null);
            }
        }
        if (TypeConstant.NEWS_NORMAL.equals(news.getArticleType())) {
            MobclickAgentUtils.event(UmEventId.articleabout_exposed, "相关文章");
        } else if (TypeConstant.VIDEO_NORMAL.equals(news.getArticleType())) {
            MobclickAgentUtils.event(UmEventId.videoabout_exposed, "相关文章");
        }
        int type = getItemViewType(position);
        if (type == AD_TT_BIG) {
            LogUtils.e("toutiao", "AD_TT_BIG------------------");
            return getTouTiaoView(convertView, parent, position);
        }
        if (convertView == null) {
            switch (type) {
                case NEWS_THREE_IMAGE_WITH_NUM://商品的 三图带数量角标
                case NEWS_THREE_IMAGE://三张图
                    convertView = inflater.inflate(R.layout.item_about_newslist_three, null);
//                    ViewNewsThreeImg viewNewsThreeImg = new ViewNewsThreeImg(convertView, 300, 215);
                    ViewNewsThreeImg viewNewsThreeImgWithNum = new ViewNewsThreeImg(convertView);
                    viewNewsThreeImgWithNum.loadData(news);
                    break;
                case NEWS_NO_IMAGE://没有图
                    convertView = inflater.inflate(R.layout.item_about_newslist_no_image, null);
                    ViewNewsNoImg viewNewsNoImg = new ViewNewsNoImg(convertView);
                    viewNewsNoImg.loadData(news);
                    break;
                case NEWS_ONE_IMAGE://一张图
                    convertView = inflater.inflate(R.layout.item_about_newslist_normal, null);
//                    ViewNewsSmallImg viewNewsSmallImg = new ViewNewsSmallImg(convertView, 300, 215);
                    ViewNewsSmallImg viewNewsSmallImg = new ViewNewsSmallImg(convertView);
                    viewNewsSmallImg.loadData(news);
                    break;
//                    ViewNewsThreeImg viewNewsThreeImg = new ViewNewsThreeImg(convertView, 300, 215);
                case NEWS_BIG_IMAGE://文章大图(适配文章 图集 视频的大图)
                    convertView = inflater.inflate(R.layout.item_about_newslist_big_news_image, null);
                    ViewNewsBigImg viewNewsBigImg = new ViewNewsBigImg(convertView);
//                    viewNewsBigImg.mConvertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    viewNewsBigImg.loadData(news);
                    break;
                case VIDEO_ONE_IMAGE://小图视频
                    convertView = inflater.inflate(R.layout.item_about_newslist_video_normal, null);
//                    ViewVideoSmallImg viewVideoSmallImg = new ViewVideoSmallImg(convertView, 300, 215);
                    ViewVideoSmallImg viewVideoSmallImg = new ViewVideoSmallImg(convertView);
//                    viewVideoSmallImg.mConvertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    viewVideoSmallImg.loadData(news);
                    break;
                case GAMEN_VIDEO_CUSTOM://没有播放按钮的游戏视频
                    convertView = inflater.inflate(R.layout.ad_game_video_three_about, null);
//                    ViewGameVideoThree viewGameVideoThree = new ViewGameVideoThree(convertView, 300, 215);
                    ViewGameVideoThree viewGameVideoThree = new ViewGameVideoThree(convertView);
                    viewGameVideoThree.loadData(news);
                    break;
                case GAMEN_VIDEO_SMALL://小图游戏视频
                    convertView = inflater.inflate(R.layout.ad_game_video_about_small, null);
//                    ViewGameVideoSmallImg viewGameVideoSmallImg = new ViewGameVideoSmallImg(convertView, 300, 215);
                    ViewGameVideoSmallImg viewGameVideoSmallImg = new ViewGameVideoSmallImg(convertView);
                    viewGameVideoSmallImg.loadData(news);
                    break;
                case TOPIC_SMALL://话题小图
                    convertView = inflater.inflate(R.layout.item_newslist_topic_small, null);
                    ViewNewsTopicSmall viewNewsTopicSmall = new ViewNewsTopicSmall(convertView);
                    viewNewsTopicSmall.loadData(news);
                    break;
                case TOPIC_BIG://话题大图
                    convertView = inflater.inflate(R.layout.item_newslist_topic_big, null);
                    ViewNewsTopicBig viewNewsTopicBig = new ViewNewsTopicBig(convertView);
                    viewNewsTopicBig.loadData(news);
                    break;

                default:
                    convertView = inflater.inflate(R.layout.item_layout_gone, null);
                    break;
            }
        } else {
            switch (type) {
                case NEWS_THREE_IMAGE_WITH_NUM://商品的 三图带数量角标
                case NEWS_THREE_IMAGE:
                    ViewNewsThreeImg viewNewsThreeImgWitNum = (ViewNewsThreeImg) convertView.getTag();
                    viewNewsThreeImgWitNum.loadData(news);
                    break;
                case NEWS_NO_IMAGE:
                    ViewNewsNoImg viewNewsNoImg = (ViewNewsNoImg) convertView.getTag();
                    viewNewsNoImg.loadData(news);
                    break;
                case NEWS_ONE_IMAGE:
                    ViewNewsSmallImg viewNewsSmallImg = (ViewNewsSmallImg) convertView.getTag();
                    viewNewsSmallImg.loadData(news);
                    break;
                case NEWS_BIG_IMAGE:
                    ViewNewsBigImg viewNewsBigImg = (ViewNewsBigImg) convertView.getTag();
                    viewNewsBigImg.loadData(news);
                    break;
                case VIDEO_ONE_IMAGE:
                    ViewVideoSmallImg viewVideoSmallImg = (ViewVideoSmallImg) convertView.getTag();
                    viewVideoSmallImg.loadData(news);
                    break;
                case GAMEN_VIDEO_CUSTOM:
                    ViewGameVideoThree viewGameVideoThree = (ViewGameVideoThree) convertView.getTag();
                    viewGameVideoThree.loadData(news);
                    break;
                case GAMEN_VIDEO_SMALL://小图戏视频
                    ViewGameVideoSmallImg viewGameVideoSmallImg = (ViewGameVideoSmallImg) convertView.getTag();
                    viewGameVideoSmallImg.loadData(news);
                    break;
                case TOPIC_SMALL:
                    ViewNewsTopicSmall viewNewsTopicSmall = (ViewNewsTopicSmall) convertView.getTag();
                    viewNewsTopicSmall.loadData(news);
                    break;
                case TOPIC_BIG:
                    ViewNewsTopicBig viewNewsTopicBig = (ViewNewsTopicBig) convertView.getTag();
                    viewNewsTopicBig.loadData(news);
                    break;
                default:
                    convertView = inflater.inflate(R.layout.item_layout_gone, null);
                    break;
            }
        }

        return convertView;
    }


    @Override
    public int getViewTypeCount() {
        return 23;
    }

    /**
     * 得到UI类型
     *
     * @param position
     * @return
     */
    @Override
    public int getItemViewType(int position) {
        NewsEntity news = list.get(position);
        if (news == null) {
            return DEFAULT;
        }
        // 文章类型(1.普通文章、2.普通图集、3普通视频 4.电商文章 5.网页文章
        // 6.电商网页软文 7.网页视频 8.轻专题 9.广告)
        switch (news.getArticleType()) {
            case TypeConstant.SHOP_ALI: {//商品的图文类型
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return NEWS_NO_IMAGE;
                } else if (TypeConstant.NEWS_UI_SMALL_IMG.equals(news.getUiType())) {
                    //小图
                    if (news.getArticleThumb().length >= 1 && news.getArticleThumb().length < 3) {
                        return NEWS_ONE_IMAGE;
                    } else if (news.getArticleThumb().length >= 3) {
                        return NEWS_THREE_IMAGE;
                    } else {
                        return NEWS_NO_IMAGE;
                    }
                } else {
                    //大图
                    return NEWS_BIG_IMAGE;
                }
            }
            case TypeConstant.SHOP_ALI_PIC: {//商品的图库类型
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return NEWS_NO_IMAGE;
                } else if (TypeConstant.NEWS_UI_BIG_TWO_IMG.equals(news.getUiType())) {//新闻栏目的大图
                    return NEWS_BIG_IMAGE;
                } else if (TypeConstant.NEWS_UI_SMALL_IMG.equals(news.getUiType())) {
                    if (news.getArticleThumb().length >= 1 && news.getArticleThumb().length < 3) {
                        return NEWS_ONE_IMAGE;
                    } else if (news.getArticleThumb().length >= 3) {
                        return NEWS_THREE_IMAGE_WITH_NUM;
                    }
                }
            }
            case TypeConstant.POST_2052://新版话题
            {
                if (TextUtils.equals(news.getUiType(), TypeConstant.NEWS_UI_SMALL_IMG)) {
                    return TOPIC_SMALL;
                } else if (TextUtils.equals(news.getUiType(), TypeConstant.NEWS_UI_BIG_ONE_IMG) ||
                        TextUtils.equals(news.getUiType(), TypeConstant.NEWS_UI_BIG_TWO_IMG)) {
                    return TOPIC_BIG;
                } else {
                    return DEFAULT;
                }
            }
            //适配所有文章
            case TypeConstant.NEWS_NORMAL:
            case TypeConstant.NEWS_SHOP:
            case TypeConstant.NEWS_WEB:
            case TypeConstant.NEWS_SHOP_WEB:
                //适配新闻专题
            case TypeConstant.NEWS_TOPIC:
            case TypeConstant.NEWS_MARKET:
            case TypeConstant.GAME_RAIDERS_TEXT://游戏图文攻略
            case TypeConstant.GAME_RAIDERS_VIDEO://游戏视频攻略
            {
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return NEWS_NO_IMAGE;
                } else if (TypeConstant.NEWS_UI_SMALL_IMG.equals(news.getUiType())) {
                    //小图
                    if (news.getArticleThumb().length >= 1) {
                        return NEWS_ONE_IMAGE;
                    } else {
                        return NEWS_NO_IMAGE;
                    }
                } else {
                    //大图
                    return NEWS_BIG_IMAGE;
                }
            }
            //适配所有图集
            case TypeConstant.PIC_NORMAL:
            case TypeConstant.PIC_TOPIC: {
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return NEWS_NO_IMAGE;
                } else if (TypeConstant.NEWS_UI_SMALL_IMG.equals(news.getUiType())) {
                    return NEWS_ONE_IMAGE;
                } else if (TypeConstant.NEWS_UI_BIG_ONE_IMG.equals(news.getUiType())) {
                    return NEWS_BIG_IMAGE;
                } else if (TypeConstant.NEWS_UI_BIG_TWO_IMG.equals(news.getUiType())) {
                    return NEWS_BIG_IMAGE;
                }
            }
            //适配所有视频
            case TypeConstant.VIDEO_NORMAL:
            case TypeConstant.VIDEO_WEB: {
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return NEWS_NO_IMAGE;
                } else if (TypeConstant.NEWS_UI_SMALL_IMG.equals(news.getUiType())) {
                    return VIDEO_ONE_IMAGE;
                } else if (TypeConstant.NEWS_UI_BIG_ONE_IMG.equals(news.getUiType())) {
                    return NEWS_BIG_IMAGE;
                } else if (TypeConstant.NEWS_UI_BIG_TWO_IMG.equals(news.getUiType())) {
                    return NEWS_BIG_IMAGE;
                }
            }
            //游戏视频
            case TypeConstant.GAME_VIDEO: {
                if (news.getArticleThumb() == null || news.getArticleThumb().length == 0) {
                    return DEFAULT;
                } else if (TextUtils.equals(news.getShowPlayBtn(), "0")) {
                    return GAMEN_VIDEO_CUSTOM;
                } else if (TextUtils.equals(news.getUiType(), TypeConstant.NEWS_UI_SMALL_IMG)) {
                    //小图
                    return GAMEN_VIDEO_SMALL;
                } else if (!TextUtils.isEmpty(news.getUiType()) && !TextUtils.equals(news.getUiType(), "0")) {
                    //大图
                    return GAMEN_VIDEO_CUSTOM;
                }
            }
            //适配所有广告类型
            case TypeConstant.AD: {
                if (news.getNativeAd() == null) {
                    return DEFAULT;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_GAME)) {
                    return GAMEN_PIC_NEWS;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_BAIDU) &&
                        TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_SMALL)) {
                    return AD_SMALL_BAIDU;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_BAIDU) &&
                        TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_BIG)) {
                    return AD_BIG_BAIDU;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_GDT) &&
                        TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_BIG)) {
                    return AD_BIG_GDT;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_GDT) &&
                        TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_SMALL)) {
                    return AD_SMALL_GDT;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_TOUTIAO)) {
//                    if (TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_SMALL)) {
//                        return AD_TT_SMALL;
//                    } else if (TextUtils.equals(news.getNativeAd().getStyle(), AdConfig.AD_VIEW_TYPE_LIST_NATIVE_BIG)) {
//                        return AD_TT_BIG;
//                    }
                    return AD_TT_BIG;
                } else if (TextUtils.equals(news.getNativeAd().getAdType(), AdConfig.AD_TYPE_H5)) {
                    //h5广告UI匹配
                    news.nativeToNews();//广告数据转换
                    if (news.getNativeAd().getThumbList() == null
                            || news.getNativeAd().getThumbList().length == 0) {
                        return NEWS_NO_IMAGE;
                    } else if (AdConfig.AD_VIEW_TYPE_LIST_NATIVE_SMALL.equals(news.getNativeAd().getStyle())) {
                        //小图
                        if (news.getArticleThumb().length >= 1 && news.getArticleThumb().length < 3) {
                            return NEWS_ONE_IMAGE;
                        } else if (news.getArticleThumb().length >= 3) {
                            return NEWS_THREE_IMAGE;
                        } else {
                            return NEWS_NO_IMAGE;
                        }
                    } else if (AdConfig.AD_VIEW_TYPE_LIST_NATIVE_BIG.equals(news.getNativeAd().getStyle())) {
                        //大图
                        return NEWS_BIG_IMAGE;
                    }
                    return NEWS_NO_IMAGE;
                } else {
                    return DEFAULT;
                }
            }
            default:
                return DEFAULT;
        }
    }


    private static class TouTiaoView {
        FrameLayout frameLayout;
        View viewLine;
    }

    private void initTouTiaoView(View view, TouTiaoView mHolder) {
        LogUtils.e("toutiao", "initTouTiaoView------------------");
        mHolder.frameLayout = view.findViewById(R.id.view_express);
        mHolder.viewLine = view.findViewById(R.id.item_divider);
    }

    private View getTouTiaoView(View convertView, ViewGroup parent, int position) {
        final TouTiaoView holder;
        try {
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.item_toutiao_express_ad, parent, false);
                holder = new TouTiaoView();
                initTouTiaoView(convertView, holder);
                convertView.setTag(holder);
            } else {
                holder = (TouTiaoView) convertView.getTag();
            }
            initTouTiaoViewData(holder, position);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    private final SparseArray<TTNativeExpressAd> ttNativeExpressAdSparseArray = new SparseArray<>();
    private boolean flushToutiao;

    private void initTouTiaoViewData(TouTiaoView viewHolder, int position) {
        LogUtils.e("toutiao", "initTouTiaoViewData------------------");
        if (viewHolder.frameLayout == null) return;
        NewsEntity newsEntity = list.get(position);
        if (newsEntity == null) return;
        viewHolder.viewLine.setVisibility(View.VISIBLE);
        viewHolder.frameLayout.setVisibility(View.VISIBLE);
        viewHolder.frameLayout.removeAllViews();
        NativeAd nativeAd = newsEntity.getNativeAd();
        if (nativeAd == null) return;
        int nativeAdSize = 0;
        // 如果没有获取到广告则 从广告管家里获取一个新广告
        ToutiaoNativeAd adManager = ToutiaoAdManager.getInstance().getAd(nativeAd.getAdId());
        if (adManager == null) {
            ToutiaoAdManager.getInstance().putAd(nativeAd);
        } else {
            nativeAdSize = adManager.getNativeAdSize();
        }
        if (!flushToutiao) {
            TTNativeExpressAd ttNativeExpressAd = ttNativeExpressAdSparseArray.get(position);
            if (ttNativeExpressAd != null) {
                fillToutiaoView(viewHolder, position, newsEntity, ttNativeExpressAd);
                return;
            }
        }
        LogUtils.e("----------------->" + position + " flushToutiao->" + flushToutiao + "  nativeAdSize->" + nativeAdSize);
        // 如果广告缓存中有广告则开始获取
        if (nativeAdSize > 0) {
            TTNativeExpressAd nrAd = adManager.getNativeAd();
            // 如果获取的广告不为null
            if (nrAd != null) {
                fillToutiaoView(viewHolder, position, newsEntity, nrAd);
            }
        } else {
            String ad = "";
//            if (AdConfigManagerNew.localeList != null && AdConfigManagerNew.localeList.size() > 0) {
//                for (NativeAd item : AdConfigManagerNew.localeList) {
//                    if (item != null && AdConfigManagerNew.TT_AD_TYPE.equals(item.getAdType())) {
//                        ad = item.getAdId();
//                        break;
//                    }
//                }
//            }
            //用获取到的广告id去获取预加载的广告
            if (!TextUtils.isEmpty(ad)) {
                ToutiaoNativeAd bna = ToutiaoAdManager.getInstance().getAd(ad);
                if (bna != null) {
                    TTNativeExpressAd oneNrAd = bna.getNativeAd();
                    // 如果获取的广告不为null
                    if (oneNrAd != null) {
                        fillToutiaoView(viewHolder, position, newsEntity, oneNrAd);
                        return;
                    }
                }
            }
            //如果最终还是没有获取到加载好的广告,则通过广告id去请求广告
            ToutiaoNativeAd bna = ToutiaoAdManager.getInstance().getAd(nativeAd.getAdId());
            if (bna != null) {
                bna.loadOneAd(context, nativeAd.getAdId(), new ToutiaoNativeAd.NativeAdLoadCallback() {

                    @Override
                    public void onNativeAdLoad(TTNativeExpressAd ad, boolean success) {
                        if (ad != null && success) {
                            fillToutiaoView(viewHolder, position, newsEntity, ad);
                        }
                    }
                });
            }
        }

    }

    private boolean calculationHeight = true;

    private void fillToutiaoView(TouTiaoView viewHolder, int position, NewsEntity newsEntity, TTNativeExpressAd nrAd) {
        if (newsEntity == null || nrAd == null) return;
        ttNativeExpressAdSparseArray.put(position, nrAd);
        delDialogView(viewHolder, newsEntity, nrAd, position);
        View expressAdView = nrAd.getExpressAdView();
        if (expressAdView != null && expressAdView.getParent() == null) {
            viewHolder.frameLayout.addView(expressAdView);
//            nrAd.render();
        }
    }

    private void delDialogView(TouTiaoView viewHolder, NewsEntity newsEntity, TTNativeExpressAd adView, int position) {
        //使用自定义样式
        List<FilterWord> words = adView.getFilterWords();
        if (words == null || words.isEmpty()) {
            return;
        }
        ToutiaoCloseDialog toutiaoCloseDialog = new ToutiaoCloseDialog(context, words);
        toutiaoCloseDialog.setOnDislikeItemClick(new ToutiaoCloseDialog.OnDislikeItemClick() {
            @Override
            public void onItemClick(FilterWord filterWord) {
                LogUtils.e("toutiao filterWord", filterWord.getName(), "del position->" + position);
//                LiveEventBus.get(Config.EventBus.delNewsListAd, Integer.class).post(position);
//                list.remove(newsEntity);
//                notifyDataSetChanged();
                viewHolder.frameLayout.setVisibility(View.GONE);
            }
        });
        toutiaoCloseDialog.setCancelable(true);
        toutiaoCloseDialog.setCanceledOnTouchOutside(true);
        adView.setDislikeDialog(toutiaoCloseDialog);
    }

}
